// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.android.apps.moderator;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Bundle;
import android.webkit.WebView;

/**
 * An activity to display application help to the user
 */
public class HelpActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.help);

    try {
      InputStream inputStream = getAssets().open("help.html");
      byte[] buffer = new byte[inputStream.available()];
      inputStream.read(buffer);
      inputStream.close();

      WebView webView = (WebView) findViewById(R.id.webview);

      String text = new String(buffer);

      Resources resources = getResources();

      PackageManager manager = getPackageManager();
      try {
        PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
        text = text.replace("$app", 
            getText(resources.getIdentifier("app_name", "string", getPackageName())));
        text = text.replace("$ver", info.versionName);
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      }

      webView.loadData(text, "text/html", "UTF-8");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

}
